package controller;

import dto.CartInfoDTO;
import entity.Address;
import service.CartInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author
 */
@RestController
@RequestMapping("cartInfo")
public class CartInfoController {

    @Autowired
    private CartInfoService cartInfoService;

    /**
     * 查询全部数据
     *
     * @return 返回一个列表，包含所查信息
     */
    @GetMapping("queryAll")
    public ResponseEntity<List<CartInfoDTO>> queryAll(){
        return ResponseEntity.ok(cartInfoService.selectAll());
    }

    @GetMapping("queryAllByName/{proName}")
    public ResponseEntity<List<CartInfoDTO>> queryAllByName(@PathVariable("proName")String proName){
        return ResponseEntity.ok(cartInfoService.selectAllByName(proName));
    }

    @GetMapping("queryAllById/{proId}")
    public ResponseEntity<List<CartInfoDTO>> queryAllById(@PathVariable("proId")String proId){
        return ResponseEntity.ok(cartInfoService.selectAllById(proId));
    }

    @GetMapping("queryAllByUserId/{userId}")
    public ResponseEntity<List<Address>> queryAllByUserId(@PathVariable("userId")String userId){
        return ResponseEntity.ok(cartInfoService.selectAllByUserId(userId)) ;

    }

}
